#ifndef PEFILELOADER_H
#define PEFILELOADER_H

#include "AbstractFileLoader.h"
#include "windows.h"

class PESection : public FileSection
{
    Q_OBJECT
public:
    PESection(IMAGE_SECTION_HEADER *header, char *data)
    {
        m_pHeader = header;
        m_pSectionData = data;
    }

    bool isReadable();
    bool isWriteable();
    bool isExecutable();
    QString getSectionName()
    {
        return QString((char*)m_pHeader->Name);
    }
    char *getHandle()
    {
        return this->m_pSectionData;
    }
    uint getSize()
    {
        return m_pHeader->Misc.VirtualSize;
    }

private:
    IMAGE_SECTION_HEADER *m_pHeader;
    char *m_pSectionData;
};

class PEFile : public AbstractFileLoader
{
    Q_OBJECT
public:
    PEFile();
    bool load(QString fileName);
    char *getHandle();
    uint getSize();
    QList<FileSection*> getSections();
    FileSection *getSection(QString name);
private:
    IMAGE_DOS_HEADER *m_pDosHeader;
    IMAGE_NT_HEADERS32 *m_pPEHeader;
    QList<FileSection*> m_sections;
    //base address of pe image loaded in memory
    char *pMemoryMappedImage;
};

#endif // PEFILELOADER_H
